@()

<div id="exportModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 1000px">
		<div class="modal-content">
			<div class="modal-header bg-primary">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="cancel()"></button>
				<h4 class="modal-title">
					<i class="fa fa-pencil"></i>
					<span id="lblAddTitle" style="font-weight: bold">导出Pdf报告</span>
				</h4>
			</div>
			<form class="form-horizontal" id="exportForm" action="@routes.PredictController.export()"
			data-toggle="validator" method="post" target="_blank" onsubmit="return myExport()">
				<div class="modal-body">
					<div class="row-fluid">
						<input class="form-control" name="missionId" type="hidden"/>
						<input class="form-control" name="result" type="hidden"/>
						<input class="form-control" name="score" type="hidden"/>
						<input class="form-control" name="svgStr" type="hidden"/>

						<div class="form-group">
							<label class="control-label col-sm-2">标题:</label>
							<div class="col-sm-3">
								<input class="form-control" name="title" value="深圳绘云医学检验实验室"/>
							</div>
						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">诊断建议:</label>
							<div class="col-sm-8">
								<textarea class="form-control" name="danger" rows="3"></textarea>
							</div>
						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">送检单位:</label>
							<div class="col-sm-3">
								<input class="form-control" name="unit" />
							</div>
							<label class="control-label col-sm-2">地址:</label>
							<div class="col-sm-3">
								<input class="form-control" name="address"/>
							</div>
						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">姓名:</label>
							<div class="col-sm-3">
								<input class="form-control" name="name" />
							</div>
							<label class="control-label col-sm-2">性别:</label>
							<div class="col-sm-3">
								<input class="form-control" name="sex"/>
							</div>
						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">年龄:</label>
							<div class="col-sm-3">
								<input class="form-control" name="age" readonly/>
							</div>
							<label class="control-label col-sm-2">送检科室:</label>
							<div class="col-sm-3">
								<input class="form-control" name="office"/>
							</div>

						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">申请医生:</label>
							<div class="col-sm-3">
								<input class="form-control" name="doctor"/>
							</div>
							<label class="control-label col-sm-2">门诊/住院号:</label>
							<div class="col-sm-3">
								<input class="form-control" name="number" />
							</div>

						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">采样时间:</label>
							<div class="col-sm-3">
								<div class="input-group date datePicker">
									<input class="form-control" name="sampleTime" type="text">
									<span class="input-group-addon">
										<span class="glyphicon glyphicon-time"></span>
									</span>
								</div>
							</div>

							<label class="control-label col-sm-2">送检时间:</label>
							<div class="col-sm-3">
								<div class="input-group date datePicker">
									<input class="form-control" name="submitTime" />
									<span class="input-group-addon">
										<span class="glyphicon glyphicon-time"></span>
									</span>
								</div>
							</div>

						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">样本号:</label>
							<div class="col-sm-3">
								<input class="form-control" name="sample" />
							</div>

						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">样本类型:</label>
							<div class="col-sm-3">
								<select class="form-control" name="sampleType" required="required" style="border-radius: 4px;">
									<option value="血清">血清</option>
									<option value="尿液">尿液</option>
									<option value="粪便">粪便</option>
									<option value="血浆" selected>血浆</option>
									<option value="全血">全血</option>
									<option value="组织">组织</option>
								</select>
							</div>
							<label class="control-label col-sm-2">样本状态:</label>
							<div class="col-sm-3">
								<input class="form-control" name="sampleStatus"/>
							</div>
						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">检验:</label>
							<div class="col-sm-3">
								<input class="form-control" name="reporter"/>
							</div>
							<label class="control-label col-sm-2">审核:</label>
							<div class="col-sm-3">
								<input class="form-control" name="checker"/>
							</div>
						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">检验日期:</label>
							<div class="col-sm-3">
								<div class="input-group date datePicker">
									<input class="form-control" name="checkDate"/>
									<span class="input-group-addon">
										<span class="glyphicon glyphicon-time"></span>
									</span>
								</div>
							</div>
							<label class="control-label col-sm-2">报告日期:</label>
							<div class="col-sm-3">
								<div class="input-group date datePicker">
									<input class="form-control" name="reportDate"/>
									<span class="input-group-addon">
										<span class="glyphicon glyphicon-time"></span>
									</span>
								</div>
							</div>
						</div>

						<h4>数据</h4>

						<div class="form-group">
							<label class="control-label col-sm-2">L-亮氨酸（Leu）:</label>
							<div class="col-sm-3">
								<input class="form-control" name="leu" readonly/>
							</div>
							<label class="control-label col-sm-2">L-异亮氨酸（Ile）:</label>
							<div class="col-sm-3">
								<input class="form-control" name="ile" readonly/>
							</div>
						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">L-缬氨酸（Val）:</label>
							<div class="col-sm-3">
								<input class="form-control" name="val" readonly/>
							</div>
							<label class="control-label col-sm-2">L-苯丙氨酸（Phe）:</label>
							<div class="col-sm-3">
								<input class="form-control" name="phe" readonly/>
							</div>
						</div>

						<div class="form-group">
							<label class="control-label col-sm-2">L-酪氨酸（Tyr）:</label>
							<div class="col-sm-3">
								<input class="form-control" name="tyr" readonly/>
							</div>
						</div>

					</div>
				</div>
				<div class="modal-footer bg-info">
					<input type="hidden" id="id" name="id" />
					<button type="submit" class="btn blue" >
						确定</button>
					<button type="button" class="btn green" data-dismiss="modal" onclick="cancel()">
						取消</button>
				</div>
			</form>
		</div>
	</div>
</div>

<script>

		var missionJson = {}
		var extraDataJson = {}
		var pdfInfo = {}

		$(function () {
			getPdfInfo()
		})

		function getPdfInfo() {
			$.ajax({
				url: "@routes.UserController.getPdfInfo()",
				type: "get",
				success: function (data) {
					pdfInfo = data
				}
			});
		}

		function inputVal(key) {
			var value = ""
			if (extraDataJson[key] != "") {
				value = extraDataJson[key]
			} else {
				value = pdfInfo[key]
			}
			$("#exportForm input[name='" + key + "']").val(value)
		}

		function pdfInfoVal() {
			var array = ["title", "unit", "address", "reporter", "checker"]
			$.each(array, function (i, v) {
				inputVal(v)
			})
		}

		function myExport() {
			var sampleTime = $("input[name='sampleTime']").val()
			var submitTime = $("input[name='submitTime']").val()
			var b = true
			var message = ""
			if (sampleTime != "" && submitTime != "") {
				sampleTime = new Date(sampleTime)
				submitTime = new Date(submitTime)
				if (sampleTime > submitTime) {
					b = false
					message = "采样时间不能大于送检时间"
				}
			}
			var checkDate = $("input[name='checkDate']").val()
			var reportDate = $("input[name='reportDate']").val()
			if (checkDate != "" && reportDate != "") {
				reportDate = new Date(reportDate)
				checkDate = new Date(checkDate)
				if (checkDate > reportDate) {
					b = false
					message = "检验日期不能大于报告日期"
				}
			}
			if (!b) {
				layer.msg(message, {
					icon: 5,
					time: 3000
				});
			}

			return b;
		}

		$(".datePicker").datetimepicker({
			format: "yyyy-mm-dd hh:ii:ss",
			autoclose: true,
			language: "zh-CN"
		})


		function showExport() {
			$.ajax({
				url: "@routes.ToolController.getServerTime()",
				type: "get",
				success: function (data) {
					showExportVal(data)
				}
			});
		}

		function showExportVal(time) {
			$("#exportModal").modal("show")
			$("#exportForm input[name='age']").val(missionJson.age)
			$("#exportForm input[name='sample']").val(extraDataJson.sampleId)
			$("#exportForm input[name='missionId']").val(missionJson.id)
			$("#exportForm input[name='name']").val(extraDataJson.name)
			$("#exportForm input[name='sex']").val(extraDataJson.sex)
			$("#exportForm input[name='office']").val(extraDataJson.office)
			$("#exportForm input[name='doctor']").val(extraDataJson.doctor)
			$("#exportForm input[name='number']").val(extraDataJson.number)
			$("#exportForm input[name='sampleTime']").val(extraDataJson.sampleTime)
			$("#exportForm input[name='submitTime']").val(extraDataJson.submitTime)
			$("#exportForm input[name='sampleType']").val(extraDataJson.sampleType)
			$("#exportForm input[name='sampleStatus']").val(extraDataJson.sampleStatus)
			pdfInfoVal()
			$("#exportForm input[name='checkDate']").val(extraDataJson.checkDate)
			if (extraDataJson.reportDate != "") {
				$("#exportForm input[name='reportDate']").val(extraDataJson.reportDate)
			} else {
				$("input[name='reportDate']").val(time)
			}

			$("#exportForm input[name='leu']").val(missionJson.leu)
			$("#exportForm input[name='ile']").val(missionJson.ile)
			$("#exportForm input[name='val']").val(missionJson.val)
			$("#exportForm input[name='phe']").val(missionJson.phe)
			$("#exportForm input[name='tyr']").val(missionJson.tyr)

			MyTool.dealDanger(extraDataJson)
		}

		function bootstrapValidator() {
			$('#exportForm').bootstrapValidator({
				framework: 'bootstrap',
				icon: {
					valid: 'glyphicon glyphicon-ok',
					invalid: 'glyphicon glyphicon-remove',
					validating: 'glyphicon glyphicon-refresh'
				},
				fields: {}
			});

		}



</script>